package com.jnshu.web;

import com.jnshu.dto.message.MessageListBackList;
import com.jnshu.dto.task.TaskListBackList;
import com.jnshu.service.PersonService;
import com.jnshu.tools.resultUtils.PageBean;
import com.jnshu.tools.resultUtils.ResultBean;
import lombok.extern.java.Log;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@Log
@Validated
@RestController
public class PersonController {

    @Autowired(required = false)
    PersonService personService;

    /**
     * 后台消息列表
     *
     * @return
     */
    @GetMapping(value = "/message/list")
    PageBean message(@RequestParam(name = "pageNum", required = false) Integer pageNum,
                     @RequestParam(name = "pageSize", required = false) Integer pageSize) {
        return personService.message( pageNum, pageSize);
    }

    @PostMapping(value = "/message/list/",consumes = "application/json")
    PageBean messageList(@RequestBody MessageListBackList messageListBackList){
        log.info("messageListBackList:"+messageListBackList);
        return personService.messageList(messageListBackList);
    }
    /**
     * 后台消息详情
     *
     * @param id
     * @return
     */
    @GetMapping("/message")
    ResultBean GetMessage(@RequestParam long id) {
        log.info("页面传入进来查看消息详情的ID为：" + id);
        return personService.GetMessage(id);
    }

    /**
     * 后台消息新增
     *
     * @return
     */
    @PostMapping("/message")
    ResultBean addMessage(@RequestParam(required = false) String title,
                          @RequestParam(required = false) String content,
                          @RequestParam(required = false) String url,
                          @RequestParam(required = false) Integer messageType,
                          @RequestParam(required = false) Integer pushType,
                          @RequestParam(required = false) Long pushTime,
                          @RequestParam(required = false) Integer object,
                          @RequestParam(name = "pageNum", required = false) Integer pageNum,
                          @RequestParam(name = "pageSize", required = false) Integer pageSize) {
        return personService.addMessage(title, content, url, messageType, pushType, pushTime, object, pageNum, pageSize);
    }

    /**
     * 后台消息编辑
     *
     * @return
     */
    @PutMapping("/message")
    ResultBean updateMessage(@RequestParam(required = false) Long id,
                             @RequestParam(required = false) String title,
                             @RequestParam(required = false) String content,
                             @RequestParam(required = false) String url,
                             @RequestParam(required = false) Integer messageType,
                             @RequestParam(required = false) Integer pushType,
                             @RequestParam(required = false) Long pushTime,
                             @RequestParam(required = false) Integer object,
                             @RequestParam(required = false) Integer status,
                             @RequestParam(name = "pageNum", required = false) Integer pageNum,
                             @RequestParam(name = "pageSize", required = false) Integer pageSize) {
        return personService.updateMessage(id, title, content, url, messageType, pushType, pushTime, object, status, pageNum, pageSize);
    }

    /**
     * 后台消息删除
     *
     * @param id
     * @return
     */
    @DeleteMapping("/message")
    ResultBean deleteMessage(@RequestParam long id) {
        log.info("页面传入要删除消息的ID为：" + id);
        return personService.deleteMessage(id);
    }

    /**
     * 修改后台消息上下架状态
     *
     * @param id
     * @param status
     * @return
     */
    @PutMapping("/message/status")
    ResultBean updateStatus(@RequestParam long id, @RequestParam int status) {
        log.info("要修改上下架状态的消息ID为：" + id + ",文章目前的状态为：" + status);
        return personService.updateStatus(id, status);
    }


    @GetMapping(value = "/task/list")
    public PageBean task(@RequestParam(name = "pageNum", required = false) Integer pageNum,
                             @RequestParam(name = "pageSize", required = false) Integer pageSize) {
        return personService.task(pageNum, pageSize);
    }

    @PostMapping(value = "/task/list/",produces = {"application/json;charset=UTF-8"})
    ResultBean taskList(@RequestBody TaskListBackList taskListBackList){
        return personService.taskList(taskListBackList);
    }

    /**
     * 后台任务详情
     *
     * @param id
     * @return
     */
    @GetMapping("/task")
    ResultBean getTask(@RequestParam long id) {
        log.info("页面传入进来查看消息详情的ID为：" + id);
        return personService.getTask(id);
    }

    /**
     * 后台任务新增
     *
     * @return
     */
    @PostMapping("/task")
    ResultBean addTask(@RequestParam(required = false) String title,
                       @RequestParam(required = false) Integer taskType,
                       @RequestParam(required = false) String url,
                       @RequestParam(required = false) Integer pointReward,
                       @RequestParam(required = false) Integer status,
                       @RequestParam(required = false) Integer publisher,
                       @RequestParam(name = "pageNum", required = false) Integer pageNum,
                       @RequestParam(name = "pageSize", required = false) Integer pageSize) {
        return personService.addTask(title, taskType, url, pointReward, status, publisher, pageNum, pageSize);
    }

    /**
     * 后台任务编辑
     *
     * @return
     */
    @PutMapping("/task")
    ResultBean updateTask(@RequestParam(required = false) Long id,
                          @RequestParam(required = false) String title,
                          @RequestParam(required = false) Integer taskType,
                          @RequestParam(required = false) String url,
                          @RequestParam(required = false) Integer pointReward,
                          @RequestParam(required = false) Integer status,
                          @RequestParam(required = false) Integer publisher,
                          @RequestParam(name = "pageNum", required = false) Integer pageNum,
                          @RequestParam(name = "pageSize", required = false) Integer pageSize) {
        return personService.updateTask(id, title, taskType, url, pointReward, status, publisher, pageNum, pageSize);
    }

    /**
     * 后台任务删除
     *
     * @param id
     * @return
     */
    @DeleteMapping("/task")
    ResultBean deleteTask(@RequestParam long id) {
        log.info("页面传入要删除消息的ID为：" + id);
        return personService.deleteTask(id);
    }

    /**
     * 修改后台任务上下架状态
     *
     * @param id
     * @param status
     * @return
     */
    @PutMapping("/task/status")
    ResultBean updateTaskStatus(@RequestParam long id, @RequestParam int status) {
        log.info("要修改上下架状态的消息ID为：" + id + ",文章目前的状态为：" + status);
        return personService.updateTaskStatus(id, status);
    }

    //用户列表
    @GetMapping(value = "/user/list")
    public ResultBean selectList(
            @RequestParam(name = "grade", required = false) Integer grade,
            @RequestParam(name = "nickname", required = false) String nickname,
            @RequestParam(name = "status", required = false) Integer status,
            @RequestParam(name = "emailStatus", required = false) Integer emailStatus,
            @RequestParam(name = "startTime", required = false) Long startTime,
            @RequestParam(name = "endTime", required = false) Long endTime,
            @RequestParam(name = "pageNum", required = false) Integer pageNum,
            @RequestParam(name = "pageSize", required = false) Integer pageSize) {
        log.info("_____________________________________________");
        log.info("方法managerList进来的参数为" + "," + pageSize + "," + pageNum);
        return personService.selectList(grade, nickname, status, emailStatus, startTime, endTime, pageNum, pageSize);
    }


    //用户详情
    @GetMapping("/user")
    public ResultBean selectByPrimaryKey(@RequestParam Long id) {
        log.info("_____________________________________________");
        log.info("方法managerList进来的参数为" + "," + id);
        return personService.selectByPrimaryKey(id);
    }
}
